﻿var POLICY_NUMBER = /[0-9]+/;
var POLICY_LETTER = /[A-Za-z]+/;
var POLICY_LOWERCASE = /[a-z]+/;
var POLICY_CAPITAL = /[A-Z]+/;
var POLICYSPECIALCHARACTER = /[^A-Za-z0-9]+/;

function MyComplexPolicy() { }
MyComplexPolicy.VerifyLength = function(strPassword, intMinLength) {
if (strPassword.length >= intMinLength) return true;
    else return false;
}
MyComplexPolicy.VerifyNumber = function(strPassword) {
    return POLICY_NUMBER.test(strPassword);
}
MyComplexPolicy.VerifyLetter = function(strPassword) {
    return POLICY_LETTER.test(strPassword);
}
MyComplexPolicy.VerifyLowerCase = function(strPassword) {
    return POLICY_LOWERCASE.test(strPassword);
}
MyComplexPolicy.VerifyCapital = function(strPassword) {
    return POLICY_CAPITAL.test(strPassword);
}
MyComplexPolicy.VerifySpecial = function(strPassword) {
    return POLICYSPECIALCHARACTER.test(strPassword);
}
MyComplexPolicy.Verify = function(strPwd,intComplexType, intMinLength) {
var blnResult = MyComplexPolicy.VerifyLength(strPwd, intMinLength);
    switch (intComplexType) {
        case 0: //必须包含数字、字母
            if (blnResult && MyComplexPolicy.VerifyNumber(strPwd) && MyComplexPolicy.VerifyLetter(strPwd)) blnResult = true;
            else blnResult = false;
            break;
        case 1: //必须包含数字、大小写字母
            if (blnResult && MyComplexPolicy.VerifyNumber(strPwd) && MyComplexPolicy.VerifyCapital(strPwd) && MyComplexPolicy.VerifyLowerCase(strPwd)) blnResult = true;
            else blnResult = false;
            break;
        case 2: //必须包含数字、大小写字母和特殊字符
            if (blnResult && MyComplexPolicy.VerifyNumber(strPwd) && MyComplexPolicy.VerifyCapital(strPwd) && MyComplexPolicy.VerifyLowerCase(strPwd) && MyComplexPolicy.VerifySpecial(strPwd)) blnResult = true;
            else blnResult = false;
            break;
    }
    return blnResult
}


